package aidturith.db.beans;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name = "game_table")
public class Game {

	@Id
	@GeneratedValue
	@Column(name = "game_id")
	private int game_id;

	@Column(name = "game_name", nullable = false, updatable = true, unique = true)
	private String game_name;

	@Column(name = "game_year", nullable = true, updatable = true, unique = false)
	private int game_year;

	@ManyToOne
	@JoinColumn(name = "id_serie")
	private Serie serie;

	@OneToMany(mappedBy="game")
	@Cascade({CascadeType.ALL})
	private Set<Subtitle> subtitles = new HashSet<Subtitle>();

	@OneToMany(mappedBy="game")
	@Cascade({CascadeType.ALL})
	private Set<Alias> aliases = new HashSet<Alias>();

	public Game() { super(); }

	public Game(String game_name) {
		super();
		this.game_name = game_name;
	}

	public Game(String game_name, int game_year) {
		super();
		this.game_name = game_name;
		this.game_year = game_year;
	}

	public String getGame_name() { return game_name; }
	public void setGame_name(String game_name) { this.game_name = game_name; }

	public int getGame_year() { return game_year; }
	public void setGame_year(int game_year) { this.game_year = game_year; }

	public Serie getSerie() { return serie; }
	public void setSerie(Serie serie) { this.serie = serie; }

	public Set<Subtitle> getSubtitles() { return subtitles; }
	public void setSubtitles(Set<Subtitle> subtitles) { this.subtitles = subtitles; }

	public void addSubtitle(Subtitle subtitle) {
		getSubtitles().add(subtitle);
		subtitle.setGame(this);
	}

	public Set<Alias> getAliases() { return aliases; }
	public void setAliases(Set<Alias> aliases) { this.aliases = aliases; }

	public void addAlias(Alias alias) {
		getAliases().add(alias);
		alias.setGame(this);
	}

	@Override
	public String toString() { return game_name; }

}
